<?php

class GoogleAnalytics extends BaseComponent {

	var $isNew;
    var $orderID;
    var $affiliation;
    var $total;
    var $tax = 0;
    var $shipping = 0;
    var $city;
    var $state = 'Lvivska obl.';
    var $country = 'Ukraine';
    var $productName; 
    var $category;
    var $price;
    var $quantity = 1;
    
	
	
	function setData($post = null){
		$this->isNew = $post->isNew;
	    $this->orderID = $post->id;		
    	$this->affiliation = $post->SettlementRegion;
    	$this->total = $post->Price;
    	$this->city = $post->SettlementCity;
    	$this->productName = $post->RealtyType; 
    	$this->category = $post->Action;
    	$this->price = $post->Price;
	}	
    
    function getHTML(){
    	$content = parent::getHTML();
		$commDat = '';
		if($this->isNew){
	    	//Transaction
			$commDat = file_get_contents(GOOGLE_TEMPLATES_PATH . 'eCommerce.html');
			$commDat = str_replace('[POST_ID]', $this->orderID, $commDat);		
			$commDat = str_replace('[POST_LR]', '"Lviv"', $commDat);
			$commDat = str_replace('[POST_PRICE]', $this->price, $commDat);
			$commDat = str_replace('[POST_TAX]', $this->tax, $commDat);		
			$commDat = str_replace('[POST_SHIPPING]', $this->shipping, $commDat);		
			$commDat = str_replace('[POST_CITY]', '"' . $this->city . '"', $commDat);		
			$commDat = str_replace('[POST_STATE]', '"' . $this->state . '"', $commDat);
			$commDat = str_replace('[POST_COUNTRY]', '"' . $this->country . '"', $commDat);
			//Item
			$commDat = str_replace('[POST_ID]', $this->orderID, $commDat);
			$commDat = str_replace('[POST_ACTION]', '"' . $this->category . '"', $commDat);
			$commDat = str_replace('[POST_TYPE]', '"' . $this->productName . '"', $commDat);
			$commDat = str_replace('[POST_CATEGORY]', '"' . $this->category . '"', $commDat);
			$commDat = str_replace('[POST_PRICE]', $this->price, $commDat);
			$commDat = str_replace('[POST_QUANTITY]', $this->quantity, $commDat);
		}
    	return str_replace('[GOOGLE_E_COMMERCE]', $commDat, $content);
    }



}




?>